# Unix makefile for Basilisk II

## System specific configuration
@SET_MAKE@
SHELL = /bin/sh

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
datadir = @datadir@
mandir = @mandir@
man1dir = $(mandir)/man1

DESTDIR =

CC = @CC@
CXX = @CXX@
CFLAGS = @CFLAGS@
CXXFLAGS = @CXXFLAGS@
CPPFLAGS = @CPPFLAGS@ -I../include -I. @CPUINCLUDES@
DEFS = @DEFS@ @DEFINES@ -D_REENTRANT -DDATADIR=\"$(datadir)/$(APP)\"
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
SYSSRCS = @SYSSRCS@
CPUSRCS = @CPUSRCS@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ -s
INSTALL_DATA = @INSTALL_DATA@

## Files
SRCS = ../main.cpp main_unix.cpp ../prefs.cpp ../prefs_items.cpp prefs_unix.cpp \
    sys_unix.cpp ../rom_patches.cpp ../slot_rom.cpp ../rsrc_patches.cpp \
    ../emul_op.cpp ../macos_util.cpp ../xpram.cpp xpram_unix.cpp ../timer.cpp \
    timer_unix.cpp clip_unix.cpp ../adb.cpp ../serial.cpp ../ether.cpp \
    ../sony.cpp ../disk.cpp ../cdrom.cpp ../scsi.cpp ../video.cpp video_blit.cpp \
    video_x.cpp sigsegv.cpp ../audio.cpp ../extfs.cpp extfs_unix.cpp \
	../user_strings.cpp user_strings_unix.cpp \
    $(SYSSRCS) $(CPUSRCS)
APP = BasiliskII

## Rules
.PHONY: modules install installdirs uninstall mostlyclean clean distclean depend dep
.SUFFIXES:
.SUFFIXES: .c .cpp .s .o .h

all: $(APP)

OBJ_DIR = obj
$(OBJ_DIR)::
	@[ -d $(OBJ_DIR) ] || mkdir $(OBJ_DIR) > /dev/null 2>&1

define SRCS_LIST_TO_OBJS
	$(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(foreach file, $(SRCS), \
	$(basename $(notdir $(file))))))
endef
OBJS = $(SRCS_LIST_TO_OBJS)

SRC_PATHS += $(sort $(foreach file, $(SRCS), $(dir $(file))))
VPATH :=
VPATH += $(addprefix :, $(subst  ,:, $(filter-out $($(subst, :, ,$(VPATH))), $(SRC_PATHS))))

$(APP): $(OBJ_DIR) $(OBJS)
	$(CXX) -o $(APP) $(LDFLAGS) $(OBJS) $(LIBS)

modules:
	cd Linux/NetDriver; make

install: $(APP) installdirs
	$(INSTALL_PROGRAM) $(APP) $(DESTDIR)$(bindir)/$(APP)
	-$(INSTALL_DATA) $(APP).1 $(DESTDIR)$(man1dir)/$(APP).1
	$(INSTALL_DATA) keycodes $(DESTDIR)$(datadir)/$(APP)/keycodes
	$(INSTALL_DATA) fbdevices $(DESTDIR)$(datadir)/$(APP)/fbdevices

installdirs:
	$(SHELL) mkinstalldirs $(DESTDIR)$(bindir) $(DESTDIR)$(man1dir) $(DESTDIR)$(datadir)/$(APP)

uninstall:
	rm -f $(DESTDIR)$(bindir)/$(APP)
	rm -f $(DESTDIR)$(man1dir)/$(APP).1
	rm -f $(DESTDIR)$(datadir)/$(APP)/keycodes
	rm -f $(DESTDIR)$(datadir)/$(APP)/fbdevices
	rmdir $(DESTDIR)$(datadir)/$(APP)

mostlyclean:
	rm -f $(APP) $(OBJ_DIR)/* core* *.core *~ *.bak

clean: mostlyclean
	rm -f cpuemu.cpp cpudefs.cpp cputmp*.s cpufast*.s cpustbl.cpp cputbl.h

distclean: clean
	rm -rf $(OBJ_DIR)
	rm -f Makefile
	rm -f config.cache config.log config.status config.h

depend dep:
	makedepend $(CPPFLAGS) -Y. $(SRCS) 2>/dev/null

$(OBJ_DIR)/%.o : %.c
	$(CC) $(CPPFLAGS) $(DEFS) $(CFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o : %.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o : %.s
	$(CC) $(CPPFLAGS) $(DEFS) $(CFLAGS) -c $< -o $@

$(OBJ_DIR)/cpuopti: $(OBJ_DIR)/cpuopti.o
	$(CC) $(LDFLAGS) -o $(OBJ_DIR)/cpuopti $(OBJ_DIR)/cpuopti.o
$(OBJ_DIR)/build68k: $(OBJ_DIR)/build68k.o
	$(CC) $(LDFLAGS) -o $(OBJ_DIR)/build68k $(OBJ_DIR)/build68k.o
$(OBJ_DIR)/gencpu: $(OBJ_DIR)/gencpu.o $(OBJ_DIR)/readcpu.o $(OBJ_DIR)/cpudefs.o
	$(CC) $(LDFLAGS) -o $(OBJ_DIR)/gencpu $(OBJ_DIR)/gencpu.o $(OBJ_DIR)/readcpu.o $(OBJ_DIR)/cpudefs.o
cpudefs.cpp: $(OBJ_DIR)/build68k ../uae_cpu/table68k
	$(OBJ_DIR)/build68k <../uae_cpu/table68k >cpudefs.cpp
cpustbl.cpp: cpuemu.cpp
cputbl.h: cpuemu.cpp

cpuemu.cpp: $(OBJ_DIR)/gencpu
	$(OBJ_DIR)/gencpu

$(OBJ_DIR)/cpuemu1.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_1 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu2.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_2 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu3.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_3 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu4.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_4 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu5.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_5 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu6.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_6 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu7.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_7 $(CXXFLAGS) -c $< -o $@
$(OBJ_DIR)/cpuemu8.o: cpuemu.cpp
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_8 $(CXXFLAGS) -c $< -o $@

cpufast.s: cpuemu.cpp $(OBJ_DIR)/cpuopti
	$(CXX) $(CPPFLAGS) $(DEFS) -S $(CXXFLAGS) $< -o cputmp.s
	$(OBJ_DIR)/cpuopti <cputmp.s >$@ || mv cputmp.s $@
	rm -f cputmp.s
cpufast1.s: cpuemu.cpp $(OBJ_DIR)/cpuopti
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_1 -S $(CXXFLAGS) $< -o cputmp1.s
	$(OBJ_DIR)/cpuopti <cputmp1.s >$@ || mv cputmp1.s $@
	rm -f cputmp1.s
cpufast2.s: cpuemu.cpp $(OBJ_DIR)/cpuopti
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_2 -S $(CXXFLAGS) $< -o cputmp2.s
	$(OBJ_DIR)/cpuopti <cputmp2.s >$@ || mv cputmp2.s $@
	rm -f cputmp2.s
cpufast3.s: cpuemu.cpp $(OBJ_DIR)/cpuopti
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_3 -S $(CXXFLAGS) $< -o cputmp3.s
	$(OBJ_DIR)/cpuopti <cputmp3.s >$@ || mv cputmp3.s $@
	rm -f cputmp3.s
cpufast4.s: cpuemu.cpp $(OBJ_DIR)/cpuopti
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_4 -S $(CXXFLAGS) $< -o cputmp4.s
	$(OBJ_DIR)/cpuopti <cputmp4.s >$@ || mv cputmp4.s $@
	rm -f cputmp4.s
cpufast5.s: cpuemu.cpp $(OBJ_DIR)/cpuopti
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_5 -S $(CXXFLAGS) $< -o cputmp5.s
	$(OBJ_DIR)/cpuopti <cputmp5.s >$@ || mv cputmp5.s $@
	rm -f cputmp5.s
cpufast6.s: cpuemu.cpp $(OBJ_DIR)/cpuopti
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_6 -S $(CXXFLAGS) $< -o cputmp6.s
	$(OBJ_DIR)/cpuopti <cputmp6.s >$@ || mv cputmp6.s $@
	rm -f cputmp6.s
cpufast7.s: cpuemu.cpp $(OBJ_DIR)/cpuopti
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_7 -S $(CXXFLAGS) $< -o cputmp7.s
	$(OBJ_DIR)/cpuopti <cputmp7.s >$@ || mv cputmp7.s $@
	rm -f cputmp7.s
cpufast8.s: cpuemu.cpp $(OBJ_DIR)/cpuopti
	$(CXX) $(CPPFLAGS) $(DEFS) -DPART_8 -S $(CXXFLAGS) $< -o cputmp8.s
	$(OBJ_DIR)/cpuopti <cputmp8.s >$@ || mv cputmp8.s $@
	rm -f cputmp8.s

#-------------------------------------------------------------------------
# DO NOT DELETE THIS LINE -- make depend depends on it.
